package com.lxg.service.adminService.impl;

import com.lxg.dao.UserDao;
import com.lxg.pojo.User;
import com.lxg.service.adminService.AdminUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class AdminUserServiceImpl implements AdminUserService {
    @Autowired
    UserDao userDao;


    /**
     * 查询全部用户
     * @return allUser
     */
    @Override
    public ArrayList<User> getAllUser() {
        ArrayList<User> allUser = userDao.getAllUser();
        return allUser;
    }





    /**
     * 根据sno查询用户
     * @param sno
     * @return
     */
    @Override
    public User getUserBySno(String sno) {
        User userBySno = userDao.getUserBySno(sno);
        return userBySno;
    }

    /**
     * 根据name模糊查询用户
     * @param name
     * @return allUser
     */
    @Override
    public ArrayList<User> getAllLikeUserByName(String name) {
        ArrayList<User> allUser = userDao.getAllLikeUserByName(name);
        return allUser;
    }

    @Override
    public ArrayList<User> getAllLikeUserByUserName(String username) {
        ArrayList<User> allLikeUserByUsername = userDao.getAllLikeUserByUsername(username);
        return allLikeUserByUsername;
    }


    /**
     * 根据uid删除一个用户
     * @param uid
     */
    @Override
    public boolean deleteUserByUid(Integer uid) {
        userDao.deleteUserByUid(uid);
        return true;
    }

    @Override
    public Integer getUsersNum() {
        Integer num = userDao.getNum();
        return num;
    }

    @Override
    public boolean addUser(User user) {
        userDao.addUser(user.getUsername(),user.getPassword(),user.getName(),user.getSno(),user.getGrade(),user.getEmail(),user.getPhone());
        return true;
    }

    @Override
    public boolean updateUser(String username, String password, String name, String sno, String grade, String email, String phone,Integer uid) {
        userDao.adminUpdateUser(username, password, name, sno, grade, email, phone,uid);
        return true;
    }
}
